// 原生广告
import {
  initNativeSdk,
  initBqtSdk,
  getManuAdv,
} from './native_sdk.js'
// banner广告
import {
  initBannerSdk,
  getBannerAdv,
  showBannerAdv,
  hideBannerAdv,
  destroyBannerAdv,
  setManuAdv,
  getSingleBanner
} from './banner_sdk.js'
// video广告
import {
  initVideoAdvSdk,
  playVideoReward,
  getVedioAdv,
} from './video_adv_sdk.js'
// ylh开屏
import { initYlhSplashSdk } from './ylhSplash.js'
import { eventEmitter } from './emitter.js'
var downloadTime = null
var strTime = null
var downloadList = []
var ad_sdk_global = {
  // 当前设备信息，必传
  deviceInfo: null,
  // 当前应用的包名,必传
  pkg: '',
  // 渠道号
  qudao: 'NULL',
  // 链接id
  link_id: 'NULL',
  // 是否支持厂商广告
  serviceAd: true,
  // sdk初始化状态，0未初始化，1初始化中，2初始化完成
  initStatus: 0,
  // 插屏广告id
  insertId: '',
  // 插屏广告对象
  insertAd: null,
  scenarioReward: '',
  versionCode: '',
  // 是否创建过视频广告对象

  isCreate: false,
  // 初始化时页面的名称
  pageUrl: '',
  // 策略名称
  tacticsName: '',
  // 请求失败广告位数组
  loadFailAdIdArr: [],
  // 当前广告配置模式 1: A/B组随机模式  2:保价模式  3:广告位模式
  adConfigType: 1,
  // 百青藤广告位
  ad_group_id: 'NULL', //广告组id
  ad_plan_id: 'NULL', // 广告计划id
  source_pkg: 'NULL', //来源包名
  unionid: 'NULL', // 媒体位id
  utm_content: 'NULL', // 创意id
  materialType: 1, //素材和icon优先级 1素材 2icon
  hwPageThis: null, //
  applicationInstall: 1, //华为应用安装是否需要埋点上报
  defaultAdImg: 'https://img.sysenbo.top/image/2022-06-29/adDefaultImg1.png', // 广告默认图片
  adNewPostionConfig: null,
  nativeAdData: [], // 原生ecpm广告数据
  bqtAdData: [], // 信息流ecpm广告数据
  isBqtCanShowDialog: 0,
  pageTactics: null, // 正向按钮点击，存入页面去向
  adErrorReportFlag: true, // 无广告是否诸云上报
  requestTimeLimit: 100, // 广告请求频率限制
  requestNumLimit: 10, // 广告请求失败次数限制（广告请求失败次数达到该值，按请求频率限制时间请求广告）
  videoPlaying: false,
  rewardTimer: null,
  preloadVideo: false,
  preVideoAd: null,
  rewardFlag: false, // 激励视频节流
  adHonorPower: false,
  popShowNum: 0, // 上报用户当前弹窗展示、点击次数（递增）
  _this: null,
  switchN: -1,
  switchT: 0,
  switchA: 1,
  switchCase: false,
  switchS: false,
  switchO: 0,
  switchH: null,
  isAppHide: false, // 是否退出应用
  activateList: [], // 促激活列表
  switchE: 0,
  activateType: 1, // 1：激活池，2：页面池
  activateTime: 0, // 0: 不启用，1：立即，2：onHide
  boostObj: null, // 广告组件this对象
  isActivateHide: false, // 是否促激活onHide
  activateTimer: null, // 2s后未onHide上报激活失败
  showTimers: {}, // 曝光频控定时器
  showControlList: [],// 曝光频控平台列表
  responseList: [], // 存储曝光频控广告
}

var download_progress_config = {
  adv_data: null, //监听的广告对象
  context: null, //上下文
  func_name: '', //执行函数名称
}
/**
 * 设置页面数据
 * @param {Object} context 传入的上下文
 * @param {String} funcName 函数名称
 */
function setHWAd(context, funcName) {
  download_progress_config.context = context
  download_progress_config.func_name = funcName
}
/**
 * 清除页面数据  在进度组件destory时调用
 */
function clearHWAd() {
  download_progress_config.adv_data = null
  download_progress_config.context = null
  download_progress_config.func_name = ''
}

/**
 * 广告SDK初始化
 * @param obj.deviceInfo 设备信息
 * @param obj.qudao 渠道号
 * @param obj.link_id 链接id
 * @param obj.preloadingNum 预加载的广告个数
 * @param obj.materialType 素材和icon优先级
 * @param obj.success 初始化成功回调
 * @param obj.fail 初始化失败回调
 */
function initSdk(obj) {
  return new Promise((resolve, reject) => {
    if (ad_sdk_global.initStatus == 2 && !obj.isCheckStatus) {
      obj && obj.success && obj.success()
      return resolve()
    }
    // 入参判断
    if (!obj.deviceInfo || !obj.pkg || !obj.adNewPostionConfig) {
      console.error('ADNEWSDK===>初始化部分必传字段为空，请检查')
      obj && obj.fail && obj.fail()
      return reject()
    }
    // 参数初始化
    assignParame(obj)
    // 判断手机是否支持厂商
    try {
      require('@service.ad')
    } catch (err) {
      ad_sdk_global.serviceAd = false
    }
    initBannerSdk()
    initNativeSdk()
    initVideoAdvSdk()
    initBqtSdk()
    initSourceData()
    // 初始化成功
    ad_sdk_global.initStatus = 2
    obj && obj.success && obj.success()
    resolve()
  })
}
// 初始化参数赋值
function assignParame(obj) {
  LOG('AD', 'assignParame==>arguments', obj)
  ad_sdk_global.initStatus = 1
  ad_sdk_global.nativeAdData = []
  ad_sdk_global.bqtAdData = []
  ad_sdk_global._this = obj._this
  const device = require('@system.device')
  ad_sdk_global.versionCode =
    (device.host && device.host.versionCode) || '11030001'
  let deviceObj = obj.deviceInfo
  let tembrand = deviceObj.brand && deviceObj.brand.toLowerCase()
  if (tembrand == 'huawei') {
    tembrand = 'huawei'
  } else if (tembrand == 'honor') {
    tembrand = 'honor'
  } else {
    tembrand = 'other'
  }
  deviceObj.brand = tembrand
  ad_sdk_global.deviceInfo = deviceObj
  ad_sdk_global.adHonorPower = obj.adHonorPower
  ad_sdk_global.pkg = obj.pkg
  ad_sdk_global.qudao = obj.qudao ? obj.qudao : 'NULL'
  ad_sdk_global.link_id = obj.link_id ? obj.link_id : 'NULL'
  ad_sdk_global.ad_plan_id = obj.adPlanId ? obj.adPlanId : 'NULL'
  ad_sdk_global.ad_group_id = obj.adGroupId ? obj.adGroupId : 'NULL'
  ad_sdk_global.source_pkg = obj.sourcePkg ? obj.sourcePkg : 'NULL'
  ad_sdk_global.utm_content = obj.utm_content ? obj.utm_content : 'NULL'
  ad_sdk_global.unionid = obj.unionid ? obj.unionid : 'NULL'
  ad_sdk_global.tacticsName = obj.tacticsName ? obj.tacticsName : ''
  ad_sdk_global.materialType = obj.materialType ?? 2
  ad_sdk_global.applicationInstall = obj.applicationInstall
    ? obj.applicationInstall
    : 1

  ad_sdk_global.adNewPostionConfig = obj.adNewPostionConfig
  ad_sdk_global.isBqtCanShowDialog = obj.isBqtCanShowDialog || 0
  ad_sdk_global.adErrorReportFlag =
    TACTICS_SDK.getGlobalData('ad_pool').is_none_ad_report || 0
  ad_sdk_global.adNewPostionConfig.ad_protogenesis.forEach(item => {
    ad_sdk_global.nativeAdData.push(item)
  });
  // 是否存在曝光频控
  const frequencyControl = ad_sdk_global.adNewPostionConfig.frequency_control_config
  if (frequencyControl) {
    ad_sdk_global.showControlList = frequencyControl.frequency_control.filter(v => v.flag)
  }
}
/**
 * 数组重排
 * @param advIdArr 广告位数组
 * @param isHz 请求频率开关
 * @param time 连续请求失败停止时间
 */
function computeAdvIdArr(advIdArr = [], isHz = false, time = 5000) {
  // 去空
  let curArr = [].concat(advIdArr.filter((item) => item))
  let maxLayer = curArr.length
  let curLayer = 0

  curArr = curArr.map((item) => {
    let sortItem = sortArray(item.adId.split(','), isHz, time, item.current_ctr_status)
    return {
      curIndex: 0,
      maxIndex: sortItem.length,
      adsArr: sortItem,
      ecpm: Number(item.ecpm) || 0,
      type: item.ad_type ? item.ad_type.toLowerCase() : '',
      time: Number(item.time) || 0,
      target_price: Number(item.target_price) || 0,
    }
  })
  return {
    maxLayer, //最大层级
    curLayer, //当前层级
    layers: curArr,
    yetLayer: 0, // 有广告层级
  }
}
/**
 * 数组重排
 * @param failNum 请求失败次数
 * @param isHz 请求频率开关
 * @param current_status 广告位点击率状态
 */
function sortArray(arr, isHz = false, time = 5000, current_status) {
  var temp_array = new Array()
  for (var index in arr) {
    if (isHz) {
      temp_array.push({
        id: arr[index],
        _failNum: 0,
        current_status: current_status ? current_status[arr[index]] : 1,
        get failNum() {
          return this._failNum;
        },
        set failNum(flag) {
          this._failNum++
          if (flag) {
            setTimeout(() => {
              this._failNum = 0
            }, time);
          }
        }
      })
    } else {
      temp_array.push(arr[index])
    }
  }
  return shuffle(temp_array)
}
function shuffle(arr) {
  var l = arr.length
  var index, temp
  while (l > 0) {
    index = Math.floor(Math.random() * l)
    temp = arr[l - 1]
    arr[l - 1] = arr[index]
    arr[index] = temp
    l--
  }
  LOG('AD', arr)
  return arr
}
function getMaterialUrlByAdData(adObj) {
  let materialUrl = ''
  let icon = adObj.icon && typeof adObj.icon != 'object' ? adObj.icon : ''
  let img = ''
  if (ad_sdk_global.deviceInfo.brand == 'honor') {
    img = adObj.images && adObj.images[0] ? adObj.images[0] : ''
  } else {
    img = adObj.imgUrlList && adObj.imgUrlList[0] ? adObj.imgUrlList[0] : ''
  }
  if (ad_sdk_global.materialType == 2) {
    materialUrl = icon ? icon : img
  } else {
    materialUrl = img ? img : icon
  }
  if (
    (materialUrl &&
      materialUrl.indexOf('.mp4') != -1) ||
    !materialUrl ||
    typeof materialUrl != 'string'
  ) {
    materialUrl = ad_sdk_global.defaultAdImg
  }
  return materialUrl
}
/**
 * 重置广告失败code、msg
 * @param type 失败类型（无广告）
 * @param data fail、adError回调值
 */
const errMsgFormat = (type = '', data = '') => {
  let err = ''
  if (data && typeof data === 'object') {
    err = data.errCode ? data.errCode : '无errCode';
    err = `${err}-${data.errMsg ? data.errMsg : '无errMsg'}`;
  } else {
    err = JSON.stringify(data)
  }
  return type + err
}
/**
 * 广告按钮点击
 * @param {*} obj 广告对象
 */
function clickManuAdvForBtn(obj, pageName, clickType) {
  if (obj && obj.advDetail && obj.advDetail.adId) {
    uploadAdInfo('click', obj, clickType)
    if (obj.type == 'manu_ad') {
      if (
        ad_sdk_global.deviceInfo.brand == 'huawei' &&
        ad_sdk_global.deviceInfo.platformVersionCode > 1077
      ) {
        download_progress_config.adv_data = obj
        const { context, func_name, adv_data } = download_progress_config
        if (context && func_name && adv_data) {
          context[func_name](adv_data)
        }
        try {
          addObjAdv(Object.assign({}, obj), pageName)
        } catch (error) {
          console.log('onStatusChanged======00000', error)
        }
      }
      // 华为adBtn静默下载
      if (obj.isSilentDown) {
        ad_sdk_global.switchS = false
        return
      }
      obj.reportAdClick &&
        obj.reportAdClick({
          adId: obj.advDetail.adId,
        })
    }
  }
}
/**
 * 广告图片点击
 * @param {*} obj 广告对象
 */
function clickManuAdvForImg(obj, pageName, clickType) {
  LOG('AD', `广告ADSDK========>广告图片点击`, obj)
  if (obj && obj.advDetail && obj.advDetail.adId) {
    uploadAdInfo('click', obj, clickType)
    if (obj.type == 'manu_ad') {
      if (
        ad_sdk_global.deviceInfo.brand == 'huawei' &&
        ad_sdk_global.deviceInfo.platformVersionCode > 1077
      ) {
        download_progress_config.adv_data = obj
        const { context, func_name, adv_data } = download_progress_config
        if (context && func_name && adv_data) {
          context[func_name](adv_data)
        }
        try {
          addObjAdv(Object.assign({}, obj), pageName)
        } catch (error) {
          console.log('onStatusChanged======00000', error)
        }
      }
      obj.reportAdClick &&
        obj.reportAdClick({
          adId: obj.advDetail.adId,
        })
    }
  }
}

function addObjAdv(obj, pageName) {
  let downloadTypes = [103, 106, 107, 108, 101, 102, 110]
  if (downloadTypes.includes(obj.advDetail.creativeType)) {
    let downloadstatus = obj.getAppStatus({ adId: obj.advDetail.adId })
    if (downloadstatus != 'INSTALLED') {
      downloadList.push(Object.assign(obj, { isReport: false }))
      if (!downloadTime) {
        isDownloadAd(obj)
        strTime = setTimeout(() => {
          clearTimeout(downloadTime)
          clearTimeout(strTime)
          strTime = null
          downloadTime = null
          console.log('onStatusChanged=====555 ')
        }, 5 * 60 * 1000)
      }
      let param = {
        id: obj.id,
        ad_network: obj.ad_network,
        ad_type: obj.ad_type,
        page_name: obj.scenario || '厂商联盟广告',
        page_type: obj.popGroupName || '广告池',
        ad_position: obj.popName || '广告池',
        ext_field_9: obj.requestNum + '',
        ad_style: obj.ad_style,
        referer: obj.adTurn + '',
        ext_field_8: obj.advDetail.appInfo
          ? obj.advDetail.appInfo.appName
          : obj.advDetail.appName || obj.title || obj.advDetail.title || '',
        ext_field_2: obj.layer >= 0 ? obj.layer + 1 + '' : '1',
        scene: obj.scene,
        result: isDownType(obj) == 2 ? '是' : '否',
      }
      COMMON_REPORT_UTILS.ad_download_report(param)
    } else {
      COMMON_REPORT_UTILS.app_rise(obj, pageName)
    }
  }
}
/**
 * 判断是否带下载按钮
 * @param {广告对象}
 */
function isDownloadAd(obj) {
  let reportNum = 0
  console.log('onStatusChanged=====000000 ')
  for (var i = 0; i < downloadList.length; i++) {
    if (downloadList[i].isReport) {
      reportNum++
      continue
    }
    let downloadstatus = downloadList[i].getAppStatus({
      adId: downloadList[i].advDetail.adId,
    })
    console.log('onStatusChanged=====1111 ', downloadstatus)
    if (downloadstatus === 'INSTALLED') {
      reportNum++
      downloadList[i].isReport = true
      uploadAdInfo('install', downloadList[i])
      console.log('onStatusChanged=====444 ', downloadstatus)
      if (obj.isSilentDown && !ad_sdk_global.isAppHide && ad_sdk_global.activateTime) {
        // 促激活
        updateActivateList(obj)
      }
    }
  }
  if (downloadList.length == reportNum) {
    clearTimeout(downloadTime)
    clearTimeout(strTime)
    strTime = null
    downloadTime = null
    return
  }
  downloadTime = setTimeout(() => {
    isDownloadAd(obj)
  }, 5000)
}
// 促激活成功
const activateSuccess = () => {
  if (ad_sdk_global.isActivateHide) {
    clearTimeout(ad_sdk_global.activateTimer)
    ad_sdk_global.activateTimer = null
    let obj = ad_sdk_global.activateList[0]
    COMMON_REPORT_UTILS.ad_activate_report({
      id: obj.id,
      ad_network: obj.ad_network,
      ad_type: obj.ad_type,
      scene: ad_sdk_global.activateTime == 1 ? '立即' : '大腿',
      page_type: ad_sdk_global.activateType == 1 ? '激活池' : '页面池',
      ext_field_8: obj.title,
      result: '成功'
    })
    $utils.getStorage('sourceAdData').then(res => {
      const data = res && JSON.parse(res) || null
      let sourceObj = data || { source: [], expirationTime: new Date().getTime() + 24 * 60 * 60 * 1000 }
      sourceObj.source.push(obj.title)
      $utils.setStorage('sourceAdData', sourceObj)
      ad_sdk_global.activateList.shift()
      console.log(sourceObj, 'activateList-----已激活')
    })
  }
}
/**
 * 激活广告
 * @param type 激活时机类型 1:安装完成立即激活，2：大腿激活(不支持)
 */
const activateBoostAd = (type = 1) => {
  if (ad_sdk_global.activateList.length <= 0) {
    return
  }
  if (ad_sdk_global.activateTime == type) {
    let obj = ad_sdk_global.activateList[0]
    let params = {
      id: obj.id,
      ad_network: obj.ad_network,
      ad_type: obj.ad_type,
      scene: ad_sdk_global.activateTime == 1 ? '立即' : '大腿',
      page_type: ad_sdk_global.activateType == 1 ? '激活池' : '页面池',
      ext_field_8: obj.title,
      result: '发起',
    }
    COMMON_REPORT_UTILS.ad_activate_report(params)
    if (ad_sdk_global.activateType == 1) {
      // 激活池
      updateSourceData(obj)
    } else {
      // 页面池
      ad_sdk_global.boostObj && ad_sdk_global.boostObj.activateBoostAd()
    }
    // 2s内未onHide，上报激活失败
    ad_sdk_global.activateTimer = setTimeout(() => {
      params.result = '失败'
      COMMON_REPORT_UTILS.ad_activate_report(params)
      $utils.getStorage('sourceAdData').then(res => {
        const data = res && JSON.parse(res) || null
        let sourceObj = data || { source: [], expirationTime: new Date().getTime() + 24 * 60 * 60 * 1000 }
        sourceObj.source.push(obj.title)
        $utils.setStorage('sourceAdData', sourceObj)
        ad_sdk_global.activateList.shift()
        console.log(sourceObj, ad_sdk_global.activateList, 'activateList-----激活失败')
        // 通知广告池删除该广告主
        ad_sdk_global.boostObj && ad_sdk_global.boostObj.activateBoostAd(2)
      })
    }, 2000)
  }
}
// 更新促激活列表、已激活广告来源
const updateSourceData = (obj) => {
  ad_sdk_global.isActivateHide = true
  obj.reportAdClick({
    adId: obj.advDetail.adId,
  })
  // 通知广告池删除该广告主
  ad_sdk_global.boostObj && ad_sdk_global.boostObj.activateBoostAd(2)
}
// 该广告当天是否可促激活
const updateActivateList = (obj) => {
  $utils.getStorage('sourceAdData').then(res => {
    const data = res && JSON.parse(res) || null
    const isActivate = data ? data.source.indexOf(obj.title) : -1
    if (isActivate == -1) {
      ad_sdk_global.activateList.push(obj)
      ad_sdk_global.activateList.sort((a, b) => b.layer - a.layer);
      console.log(isActivate, data, ad_sdk_global.activateList, 'activateList-----促激活')
      activateBoostAd(1)
    } else {
      // 通知广告池删除该广告主
      ad_sdk_global.boostObj && ad_sdk_global.boostObj.activateBoostAd(2)
    }
  })
}
/**
 * 初始化促激活广告过期时间
 * @param source 广告主来源列表
 * @param expirationTime 过期时间为当天
 */
const initSourceData = () => {
  $utils.getStorage('sourceAdData').then(res => {
    if (res && new Date().getTime() > res.expirationTime) {
      res.expirationTime = new Date().getTime() + 24 * 60 * 60 * 1000
      res.source = []
      $utils.setStorage('sourceAdData', res)
    }
  })
}
function isDownType(obj) {
  if (obj && !obj.getAppStatus) return
  const downType = obj.getAppStatus({ adId: obj.advDetail.adId }).toLowerCase()
  const download = ['download', 'downloadfailed', 'pause']
  const downloading = ['downloading', 'waiting', 'install', 'installing']
  if (download.includes(downType)) {
    return '2'
  } else if (downloading.includes(downType)) {
    return '3'
  } else {
    return '1'
  }
}

/**
 * 更新全局数据 ad_sdk_global
 * @param {Object} obj
 * @returns
 */
function updataAdGlobalData(obj) {
  try {
    Object.assign(ad_sdk_global, obj)
    LOG('AD', `广告ADSDK========>ad_sdk_global数据更新完成`, ad_sdk_global, obj)
  } catch (error) {
    LOG('AD', `广告ADSDK========>ad_sdk_global数据更新失败`, error)
  }
}

function uploadAdInfo(eventId, obj, clickType = 'btn') {
  if (!obj || !obj.id) return
  let postParam = new Object()
  postParam.ad_id = obj.id
  postParam.ad_network = obj.ad_network || 1
  postParam.ad_type = obj.ad_type || '原生'
  postParam.result = obj.result || ''
  postParam.page_name = obj.scenario || '厂商广告联盟'
  postParam.ad_position = obj.popName || '广告池'
  postParam.page_type = obj.popGroupName || '广告池'
  postParam.ad_style = obj.ad_style || '无'
  postParam.requestNum = `${obj.requestNum || '1'}`
  postParam.ext_field_8 = obj.advDetail
    ? obj.advDetail.appInfo
      ? obj.advDetail.appInfo.appName
      : obj.advDetail.appName || obj.title || obj.advDetail.title
    : '无'
  postParam.ext_field_2 = obj.layer >= 0 ? obj.layer + 1 + '' : '1'
  postParam.referer = obj.adTurn + '' || '1'
  postParam.scene = obj.scene || '自动请求'
  postParam.ext_field_3 = obj.brand == 'huawei' ? obj.silentDown + '' || '' : obj.adRegion || ''
  postParam.ext_field_6 = obj.client || ''
  postParam.ext_field_1 = obj.isBidding && obj.advDetail ? obj.advDetail.ecpm + '' : ''
  let element = clickType == 'btn' ? '按钮' : '素材'
  let {
    ad_id,
    ad_network,
    ad_type,
    page_name,
    page_type,
    ad_position,
    result,
    ad_style,
    requestNum,
    ext_field_8,
    ext_field_2,
    referer,
    scene,
    ext_field_3,
    ext_field_6,
    ext_field_1
  } = postParam
  const ext_field_9 = requestNum
  LOG('AD', 'uploadAdInfo==============>', eventId, postParam, clickType)
  switch (eventId) {
    case 'request':
      if (!ad_sdk_global.adErrorReportFlag && obj.result.includes('无广告'))
        return
      COMMON_REPORT_UTILS.ad_sdk_request_report(
        ad_id,
        ad_network,
        ad_type,
        page_name,
        page_type,
        ad_position,
        result,
        ext_field_9,
        ad_style,
        ext_field_8,
        ext_field_2,
        referer,
        scene,
        ext_field_1
      )
      break
    case 'show':
      COMMON_REPORT_UTILS.ad_sdk_show_report(
        ad_id,
        ad_network,
        ad_type,
        page_name,
        page_type,
        ad_position,
        ext_field_9,
        ad_style,
        result,
        ext_field_8,
        ext_field_2,
        referer,
        scene,
        ext_field_1
      )
      break
    case 'click':
      ad_sdk_global.switchS = true
      COMMON_REPORT_UTILS.ad_sdk_click_report(
        ad_id,
        ad_network,
        ad_type,
        page_name,
        page_type,
        ad_position,
        element,
        ext_field_9,
        ad_style,
        ext_field_8,
        ext_field_2,
        referer,
        scene,
        ext_field_1,
        ext_field_3,
        ext_field_6,
      )
      break
    case 'render':
      COMMON_REPORT_UTILS.ad_sdk_render_report(
        ad_id,
        ad_network,
        ad_type,
        page_name,
        page_type,
        ad_position,
        ext_field_9,
        ad_style,
        referer,
        ext_field_8,
        ext_field_2,
        result,
        scene,
        ext_field_1
      )
      break
    case 'abandon':
      COMMON_REPORT_UTILS.ad_sdk_abandon_report(
        ad_id,
        ad_network,
        ad_type,
        page_name,
        page_type,
        ad_position,
        ext_field_9,
        ad_style,
        referer,
        ext_field_8,
        ext_field_2,
        result,
        '是',
        scene,
        ext_field_1
      )
      break
    case 'success':
      postParam.event_name = '视频广告播放完成SDK'
      postParam.event_id = 'ad_sdk_success'
      break
    case 'incomplete':
      postParam.event_name = '视频广告播放未完成SDK'
      postParam.event_id = 'ad_sdk_incomplete'
      break
    case 'install':
      COMMON_REPORT_UTILS.ad_sdk_install_report(
        ad_id,
        ad_network,
        ad_type,
        page_name,
        page_type,
        ad_position,
        ext_field_9,
        ad_style,
        ext_field_8,
        referer,
        ext_field_2,
        scene,
        ext_field_3,
      )
      break
    case 'take':
      COMMON_REPORT_UTILS.ad_sdk_take(
        ad_id,
        ad_network,
        ad_type,
        page_name,
        page_type,
        ad_position,
        ad_style,
        ext_field_9,
        referer,
        scene,
        ext_field_8,
        ext_field_2,
        result,
        scene,
        ext_field_1
      )
      break
    case 'control':
      COMMON_REPORT_UTILS.ad_frequency_control(postParam)
      break
  }
}
export default {
  ad_sdk_global,
  eventEmitter,
  initSdk,
  sortArray,
  computeAdvIdArr,
  getManuAdv,
  setManuAdv,
  clickManuAdvForBtn,
  clickManuAdvForImg,
  getVedioAdv,
  playVideoReward,
  getBannerAdv,
  hideBannerAdv,
  showBannerAdv,
  destroyBannerAdv,
  updataAdGlobalData,
  uploadAdInfo,
  setHWAd,
  clearHWAd,
  getMaterialUrlByAdData,
  isDownType,
  errMsgFormat,
  getSingleBanner,
  initYlhSplashSdk,
  activateSuccess
}
